import axios from '@/utils/request'
export default {
  Stock: {
    list: {
      export: {
        query: {
          '@display': `{
            'store' : 'entity.getStore().getName()',
            'material' : 'entity.getMaterial().getName()',
            'reamins' : 'entity.getRemains()',
            'currentSingleCost' : 'entity.getCurrentSingleCost()',
            'threshold' : 'entity.getThreshold()'
          }`,
          limit: 10000000
        },
        label: {
          'store': '门店',
          // 'specification': '规格',
          'material': '对应物料',
          'reamins': '库存',
          'currentSingleCost': '当前成本价',
          'threshold': '安全库存'
        }
      },
      actions: [
        {
          name: '批量同步',
          position: 'top',
          component:
            () => import('@/views/stock/add-stock-batch.vue')
        }
      ],
      list_filter: {
        'store.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        'material.id': () => {
          return axios
            .get(`/manage/materials`, { params: { limit: 10000 } })
            .then(res =>
              Object.assign({ __label: '物料' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        }
      },
      list_display: [
        'store',
        {
          property: 'material',
          label: '物料'
        },
        {
          property: 'remains',
          editable: true,
          label: '库存'
        },
        {
          property: 'currentSingleCost',
          editable: true,
          label: '成本单价'
        },
        'threshold'
      ]
    },
    form: {
      fields: [
        'store',
        // 'specification',
        {
          property: 'material',
          relation_filter: {
            limit: 1000
          },
          field_options: { label: '对应物料' }
        },
        {
          property: 'currentSingleCost',
          field_options: { label: '成本单价' },
          help: '成本单价会根据入库单进行加权平均计算'
        },
        'remains',
        'threshold'
      ]
    }
  }
}

